﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BOHVote.BLL;
using BOHVote.Common;
using System.Data;

namespace BOH.Information.Report
{
    public partial class ReportGovrenApplyList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string ApplyPeriod = string.Empty;
            string GovrenID = string.Empty;
            string GovrenName = string.Empty;
            this.Title = common.getAppSetting("AppName");
            //GovrenName = UnitClass.GetGovernName(Request.QueryString["GovrenID"]);
            if (!IsPostBack)
            {
                GovrenID = System.Text.Encoding.Default.GetString(Convert.FromBase64String(Request.QueryString["GovrenID"].ToString().Replace("%2B", "+")));
                //GovrenID = Request.QueryString["GovrenID"];
                ApplyPeriod = Request.QueryString["ApplyPeriod"];
                labApplyPeriodTitle.Text = ApplyPeriod + "年度";
                hiddenApplyPeriod.Value = ApplyPeriod;
                hiddenGovrenID.Value = GovrenID;
                GovrenName = UnitClass.GetGovernName(GovrenID);
                labGovernName.Text = GovrenName;
                this.Title = common.getAppSetting("AppName");
                string strCount = string.Empty;
                //XSD.PersonalInfo xsd = BindReport(GovrenID, ApplyPeriod, out strCount);
                //ReportViewBind(xsd, GovrenName, ApplyPeriod + "年度", strCount);
                XSD.PersonalInfo dst = dstGovernList(GovrenID, ApplyPeriod);
                BindGovrenList(dst);
            }
        }
        public void BindListofGovren()
        {
            string ApplyPeriod = string.Empty;
            string GovrenID = string.Empty;
            string GovrenName = string.Empty;
            GovrenName = UnitClass.GetGovernName(GovrenID);
            string strGovrenID = System.Text.Encoding.Default.GetString(Convert.FromBase64String(Request.QueryString["GovrenID"].ToString().Replace("%2B", "+")));
            labGovernName.Text = UnitClass.GetGovernName(strGovrenID);
            GovrenID = strGovrenID;
            ApplyPeriod = Request.QueryString["ApplyPeriod"];
            hiddenApplyPeriod.Value = ApplyPeriod;
            hiddenGovrenID.Value = GovrenID;
            XSD.PersonalInfo dst = dstGovernList(GovrenID, ApplyPeriod);
            BindGovrenList(dst);
        }

        public XSD.PersonalInfo dstGovernList(string GovrenID, string ApplyPeriod)
        {
            DataSet dst = ApplyClass.getApplyInfo("", "", GovrenID, ApplyPeriod);

            XSD.PersonalInfo personalXSD = new BOH.XSD.PersonalInfo();
            int i = 0;
            foreach (DataRow dr in dst.Tables[0].Rows)
            {
                DataRow drNew = personalXSD.Tables["PersonalInfo"].NewRow();
                drNew["NO"] = ++i;
                drNew["ApplyName"] = dr["Apply_Name"].ToString();
                drNew["UnitGovernName"] = dr["UnitGovernName"].ToString();
                drNew["ApplyPeriod"] = dr["ApplyPeriodID"].ToString();
                drNew["Gender"] = dr["Gender"].ToString();
                if (!string.IsNullOrEmpty(dr["Birthday"].ToString()))
                    drNew["Birthday"] = Convert.ToDateTime(dr["Birthday"].ToString()).ToString("yyyy-MM"); //common.changeDateFormatToDate(dr["Birthday"].ToString()).ToString("yyyy-MM-dd");
                else
                    drNew["Birthday"] = "-";

                drNew["EducationLevel"] = dr["EducationLevel"].ToString();
                drNew["IDCard"] = dr["IDCard"].ToString();
                drNew["School"] = dr["School"].ToString();

                if (!string.IsNullOrEmpty(dr["GraduationDate"].ToString()))
                    drNew["GraduationDate"] = Convert.ToDateTime(dr["GraduationDate"].ToString()).ToString("yyyy-MM");// common.changeDateFormatToDate(dr["GraduationDate"].ToString()).ToString("yyyy-MM-dd");
                else
                    drNew["GraduationDate"] = "-";

                drNew["CurrentJobRank"] = dr["CurrentJobRankID"].ToString();
                drNew["ApplyType"] = dr["ApplyType"].ToString();
                drNew["SpecialityID"] = dr["SpecialityID"].ToString();
                drNew["JobRankID"] = dr["JobRankID"].ToString();
                drNew["SubjectID"] = dr["SubjectID"].ToString();

                if (!string.IsNullOrEmpty(dr["JobDate"].ToString()))
                    drNew["JobDate"] = Convert.ToDateTime(dr["JobDate"].ToString()).ToString("yyyy-MM");
                else
                    drNew["JobDate"] = "-";

                // common.changeDateFormatToDate(dr["JobDate"].ToString()).ToString("yyyy-MM-dd");
                if (!string.IsNullOrEmpty(dr["ConversionDate"].ToString()))
                    drNew["ConversionDate"] = Convert.ToDateTime(dr["ConversionDate"].ToString()).ToString("yyyy-MM");
                else
                    drNew["ConversionDate"] = "-";

                drNew["JobTerm"] = dr["JobTerm"].ToString();
                drNew["FixedJob"] = dr["FixedJob"].ToString();
                drNew["ForeignLanguageName"] = dr["ForeignLanguageName"].ToString();
                drNew["ForeignLanguageResult"] = dr["ForeignLanguageResult"].ToString();
                drNew["PoliticsResult"] = dr["PoliticsResult"].ToString();
                drNew["JobResult"] = dr["JobResult"].ToString();
                drNew["ComputerResult"] = dr["ComputerResult"].ToString();
                drNew["ApplyPrintID"] = dr["ApplyPrintID"].ToString();

                personalXSD.Tables["PersonalInfo"].Rows.Add(drNew);

            }
            return personalXSD;        
        }

        public void BindGovrenList(XSD.PersonalInfo dst)
        {
            if (dst != null && dst.Tables[0].Rows.Count > 0)
            {
                AspNetPager1.RecordCount = dst.Tables[0].Rows.Count;
                if (AspNetPager1.RecordCount != 0)
                {
                    labNoRecord.Visible = false;
                    AspNetPager1.Visible = true;
                    PagedDataSource pds = new PagedDataSource();
                    pds.DataSource = dst.Tables[0].DefaultView;
                    pds.AllowPaging = true;
                    pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
                    labCurrentPage.Text = AspNetPager1.CurrentPageIndex.ToString() ;
                    labTotlePage.Text = AspNetPager1.PageCount.ToString();
                    labRecord.Text = AspNetPager1.PageSize.ToString();
                    pds.PageSize = AspNetPager1.PageSize;
                    GovernList.DataSource = pds;
                    GovernList.DataBind();
                }
                else
                {
                    GovernList.DataSource = null;
                    GovernList.DataBind();
                    AspNetPager1.Visible = false;
                    labNoRecord.Visible = true;
                }
            }
            else
            {
                AspNetPager1.Visible = false;
                labNoRecord.Visible = true;
                GovernList.DataSource = null;
                GovernList.DataBind();
            }
        }

        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            BindListofGovren();
        }

        protected void GovernList_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                TableCellCollection tcHeader = e.Row.Cells;
                tcHeader.Clear();

                tcHeader.Add(new TableHeaderCell());
                tcHeader[0].Attributes.Add("rowspan", "2");
                tcHeader[0].Attributes.Add("align", "center");
                tcHeader[0].Attributes.Add("width", "30px");
                tcHeader[0].Text = "流水号";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[1].Attributes.Add("rowspan", "2");
                tcHeader[1].Attributes.Add("align", "center");
                tcHeader[1].Attributes.Add("width", "220px");
                tcHeader[1].Text = "单位名称";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[2].Attributes.Add("rowspan", "2");
                tcHeader[2].Attributes.Add("align", "center");
                tcHeader[2].Attributes.Add("width", "60px");
                tcHeader[2].Text = "姓  名";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[3].Attributes.Add("rowspan", "2");
                tcHeader[3].Attributes.Add("align", "center");
                tcHeader[3].Attributes.Add("width", "35px");
                tcHeader[3].Text = "性别";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[4].Attributes.Add("rowspan", "2");
                tcHeader[4].Attributes.Add("align", "center");
                tcHeader[4].Attributes.Add("width", "60px");
                tcHeader[4].Text = "出生年月";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[5].Attributes.Add("rowspan", "2");
                tcHeader[5].Attributes.Add("align", "center");
                tcHeader[5].Attributes.Add("width", "50px");
                tcHeader[5].Text = "学   历";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[6].Attributes.Add("rowspan", "2");
                tcHeader[6].Attributes.Add("align", "center");
                tcHeader[6].Attributes.Add("width", "60px");
                tcHeader[6].Text = "毕业年月";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[7].Attributes.Add("rowspan", "2");
                tcHeader[7].Attributes.Add("align", "center");
                tcHeader[7].Attributes.Add("width", "100px");
                tcHeader[7].Text = "现任职称";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[8].Attributes.Add("rowspan", "2");
                tcHeader[8].Attributes.Add("align", "center");
                tcHeader[8].Attributes.Add("width", "60px");
                tcHeader[8].Text = "取得时间";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[9].Attributes.Add("rowspan", "2");
                tcHeader[9].Attributes.Add("align", "center");
                tcHeader[9].Attributes.Add("width", "30px");
                tcHeader[9].Text = "聘用年限";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[10].Attributes.Add("rowspan", "2");
                tcHeader[10].Attributes.Add("align", "center");
                tcHeader[10].Attributes.Add("width", "180px");
                tcHeader[10].Text = "申报专业";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[11].Attributes.Add("rowspan", "2");
                tcHeader[11].Attributes.Add("align", "center");
                tcHeader[11].Attributes.Add("width", "100px");
                tcHeader[11].Text = "申报职称";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[12].Attributes.Add("rowspan", "2");
                tcHeader[12].Attributes.Add("align", "center");
                tcHeader[12].Attributes.Add("width", "80px");
                tcHeader[12].Text = "申报类型";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[13].Attributes.Add("colspan", "5");
                tcHeader[13].Attributes.Add("align", "center");
                tcHeader[13].Attributes.Add("width", "180px");
                tcHeader[13].Text = "各项考核、考试成绩";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[14].Attributes.Add("rowspan", "2");
                tcHeader[14].Attributes.Add("align", "center");
                tcHeader[14].Attributes.Add("width", "50px");
                tcHeader[14].Text = "备   注</th></tr><tr>";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[15].Attributes.Add("align", "center");
                tcHeader[15].Attributes.Add("width", "30px");
                tcHeader[15].Text = "单位政治考核";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[16].Attributes.Add("align", "center");
                tcHeader[16].Attributes.Add("width", "30px");
                tcHeader[16].Text = "单位业务考核";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[17].Attributes.Add("align", "center");
                tcHeader[17].Attributes.Add("width", "50px");
                tcHeader[17].Text = "外语<br/>名称";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[18].Attributes.Add("align", "center");
                tcHeader[18].Attributes.Add("width", "30px");
                tcHeader[18].Text = "外语成绩";

                tcHeader.Add(new TableHeaderCell());
                tcHeader[19].Attributes.Add("align", "center");
                tcHeader[19].Attributes.Add("width", "40px");
                tcHeader[19].Text = "计算机成绩";
            }
        }

        protected void butExecl_Click(object sender, EventArgs e)
        {
            common.ToExcel(GovernList);
        }


        public override void VerifyRenderingInServerForm(Control control)
        {
        }


    }
}
